var stompClient = null;
// function setConnected(connected) {
//     document.getElementById('connect').disabled = connected;
//     document.getElementById('disconnect').disabled = !connected;
//     document.getElementById('conversationDiv').style.visibility = connected ? 'visible' : 'hidden';
//     $('#response').html();
// }

function connect() {
    var socket = new SockJS(head+'/endpointWisely');
    stompClient = Stomp.over(socket);
    stompClient.connect({}, function(frame) {
        // setConnected(true); 
        console.log('Connected:' + frame);
        stompClient.subscribe('/demo_2/topic/getResponse', function(response) {
            showResponse(response.body);
        });

    });
}


function disconnect() {
    if (stompClient != null) {
        stompClient.disconnect();
    }
    // setConnected(false); 
    console.log("Disconnected");
    console.log("Disconnected");
}

function sendName() {
    var name = $('#name').val();
    // debugger;
    stompClient.send("/app/welcome", {}, name);
}

function showResponse(message) {
    // var response = $('#response');
    // response.html(message);
    $.ajax({//获取未读消息数量
        url:head+"/repair/noReadNum",
          dataType:"json",
          type:"GET",
          data:{"managerId":id},
          success:function(redata){
              var data = redata.data;
              var repair =data.repair;
              if(repair > 0){
                $('#no_read_num').attr("style","");
                $('#no_read_num').text(repair);
              }
          }
      })
}